<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/5/9
 * Time: 上午10:47
 */

namespace App\Busi\Modules\Resource;


use App\Busi\Modules\BaseBusi;
use App\Busi\Traits\CompanyTrait;
use App\Busi\Traits\UserTrait;
use App\Exceptions\ErrorCode\UserError;
use App\Exceptions\UserException;
use App\Http\Requests\CompanyStaffGetOneRo;
use App\Models\CompanyStaff;

class CompanyStaffGetOneBusi extends BaseBusi
{
    use UserTrait,CompanyTrait;
    public function handle(CompanyStaffGetOneRo $ro){
        $id = $ro->id;
        $uid = $ro->uid;
        $user = $this->getUserByUid($uid);
        if(!$user){
            throw new UserException(UserError::USER_NOT_EXIST);
        }
        $raw_company = $this->getCompanyByUid($uid);
        if(!$raw_company){
            throw new UserException(UserError::USER_NOT_AUTH);
        }
        $company_id = $raw_company['id'];
        $where = [
            ['id','=',$id],
            ['company_id','=',$company_id]
        ];
        $fields = ['id','phone','name','avatar','experience','is_hidden'];
        $data = CompanyStaff::where($where)->select($fields)->first();
        if($data){
            $data['avatar'] = config("admin.upload.host").$data['avatar'];
        }
        return $data;
    }
}